#!/user/bin/env python3
# -*- coding: utf-8 -*-
"""
--------------------------------------
    Author:     JiChao_Song
    Date  :     2020/12/21 17:35
    Desc  :
--------------------------------------
"""
from bson import json_util

from application import mongo


class Variable(mongo.Document):
    """
    全局变量
    """

    # 变量名
    variableName = mongo.StringField()
    variableValue = mongo.StringField()
    variableDesc = mongo.StringField()
    projectId = mongo.StringField()

    def to_json(self):
        return {
            '_id': eval(json_util.dumps(self.id)),
            'variableName': self.variableName,
            'variableValue': self.variableValue,
            'variableDesc': self.variableDesc,
            'projectId': self.projectId,
        }

    def value_label(self):

        return {
            'value': self.variableValue,
            'label': f'${self.variableName}',
            'desc': self.variableDesc
        }